package main

import (
	"fmt"
	"os"
	"ucode/api_g"
	"ucode/fmt_e"
	"ucode/fmt_m"
	"ucode/fmt_sfe"
)

func main() {
	if len(os.Args) < 2 {
		fmt.Fprintln(os.Stderr, "当前支持命令列表:")
		fmt.Fprintln(os.Stderr, "1. grpc_to_api file_dir out_to_dir")
		fmt.Fprintln(os.Stderr, "2. fmt_enum_stringer filepath [enum_name] [-p]")
		fmt.Fprintln(os.Stderr, "3. fmt_pb3_message filepath [struct_name]")
		fmt.Fprintln(os.Stderr, "4. fmt_struct_field_enum filepath struct_name")
		return
	}

	var err error
	switch os.Args[1] {
	case "grpc_to_api":
		err = api_g.GrpcToApiService(os.Args[2:])
	case "fmt_enum_stringer":
		err = fmt_e.FmtFileEnumStringer(os.Args[2:])
	case "fmt_pb3_message":
		err = fmt_m.FmtPbMessageMumber(os.Args[2:])
	case "fmt_struct_field_enum":
		err = fmt_sfe.FmtStructFieldEnum(os.Args[2:])
		if err == nil {
			err = fmt_e.FmtFileEnumStringer([]string{os.Args[2], fmt.Sprintf("E%sField", os.Args[3]), "-c"})
		}
	default:
		err = fmt.Errorf("Unsupported commands were found:%q", os.Args[1])
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
	}
}
